﻿[assembly:
        System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Additions.ErrorLabelAddition.js",
                "application/x-javascript")]
[assembly:
        System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Additions.ErrorLabelAddition.debug.js",
                "application/x-javascript")]
namespace BM.Tools.WebControls.MForm.Controls.Additions
{
    using System.Web.UI.WebControls;

    using AjaxControlToolkit;

    using BM.Tools.WebControls.MForm.Controls.Items;
    using BM.Tools.WebControls.MForm.Generator;

    /// <summary>
    /// this addition adds a label near the item that displays the error message
    /// </summary>
    [ClientScriptResource("BM.Tools.WebControls.MForm",
            "BM.Tools.WebControls.MForm.Controls.Additions.ErrorLabelAddition.js")]
    public class ErrorLabelAddition : Addition
    {
        /// <summary>
        /// error label field
        /// </summary>
        private Label errorLabel;

        /// <summary>
        /// Gets ErrorLabel.
        /// </summary>
        /// <value>
        /// The error label.
        /// </value>
        public Label ErrorLabel
        {
            get
            {
                if (errorLabel == null)
                {
                    errorLabel = new Label { CssClass = "ErrorLabel" };
                }

                return errorLabel;
            }
        }

        /// <summary>
        /// adds the error label on creating child controls
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            if (Owner.Mode.Equals(FormBuilderMode.Edit))
            {
                (Owner as LeafItem).AfterValueHandlerHolder.Controls.Add(ErrorLabel);
            }
        }
    }
}